package com.zld.smarket.service.serviceImpl;

import com.zld.smarket.dao.GoodslossMapper;
import com.zld.smarket.dto.GoodsList;
import com.zld.smarket.dto.LossList;
import com.zld.smarket.dto.StockoutList;
import com.zld.smarket.pojo.Goodsloss;
import com.zld.smarket.result.ResponseData;
import com.zld.smarket.service.GoodsLossService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsLossServiceImpl implements GoodsLossService {
    @Autowired
    private GoodslossMapper goodslossMapper;
    @Override
    public ResponseData findList(Integer page, Integer limit) {
        if(page != null && limit!=null){
            page = (page-1)*limit;
        }else{
            page = 0;
            limit = 10;
        }
        List<LossList> lossLists = goodslossMapper.selectAllAndPage(page,limit);
        Long count = goodslossMapper.countAll();
        return new ResponseData(lossLists,count);
    }

    @Override
    public Long selectbyno(Long i) {
        return goodslossMapper.countLossbyno(i);
    }

    @Override
    public Integer setloss(Goodsloss goodsloss) {
        int j=0;
        j=goodslossMapper.insert(goodsloss);
        return j;
    }

    @Override
    public ResponseData search(String s, Integer page, Integer limit) {
        if(page != null && limit!=null){
            page = (page-1)*limit;
        }else{
            page = 0;
            limit = 10;
        }

        List<LossList> goodslosses =  goodslossMapper.search(s,page,limit);
        Long count = goodslossMapper.countAll();
        return new ResponseData(goodslosses,count);
    }

    @Override
    public Long totalloss() {
        return goodslossMapper.countloss();
    }
}
